package com.foreknow.penTest;

/**
 * @author shkstart
 * @create 2021-08-19 17:11
 */

import java.util.*;

/**
 * 求其每一个子串出现的次数
 * 要求：对每个字符串，输出它所有出现的次数在1次以上的子字符串，和这个子字符串出现的次数并按字典顺序排序
 */
public class Demo {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String line = null;
        while (input.hasNextLine()) {
            line = input.nextLine();
            parse(line);
        }
    }

    private static void parse(String line) {
        String subLine = null;
        Map<String, Integer> map = new TreeMap<>();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < line.length(); i++) {
            for (int j = i + 1; j <= line.length(); j++) {
                //截取子串所有的可能
                subLine = line.substring(i, j);
                //
                if (subLine.length() != line.length()) {
                    list.add(subLine);
                    map.put(subLine, 0);
                }
            }
        }
        for (int i = 0; i < list.size(); i++) {
            //map中的键值与list集合比较如果
            for (Map.Entry<String, Integer> entry : map.entrySet()) {
                if (list.get(i).equals(entry.getKey())) {
                    entry.setValue(entry.getValue() + 1);
                }
            }

        }

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() > 1) {
                System.out.println(entry.getKey() + " " + entry.getValue());
                System.out.println();
            }
        }
    }
}